﻿using BodaNetCommunications.Cores;
using BodaNetCommunications.Utilities.Tools;

using Microsoft.AspNetCore.Server.IISIntegration;

namespace BodaNetCommunications.ModbusComs.ModbusUtil
{
    public class ModbusByteTransformBase : ByteTransformBase
    {
        public override bool AnalysyseAddresType(ref string address, out Type addressType)
        {
            addressType = typeof(Nullable);
            var resParse = int.TryParse(address, out var addressTemp);
            if (!resParse) return false;

            // 如果首字母不等于0，则是数据不正确
            if (addressTemp < 10000 && address[0] != '0')
            {
                addressTemp += 40000;
                address = addressTemp.ToString();
            }

            switch (address[0])
            {
                case '0':
                    addressType = typeof(bool);
                    break;
                case '1':
                    addressType = typeof(bool);
                    break;
                case '3':
                    addressType = typeof(short);
                    break;
                case '4':
                    addressType = typeof(short);
                    break;
                default:
                    addressType = typeof(short);
                    break;
            }
            return true;
        }

    }
}
